// pages/home/home.js
Page({
  /**
   * 页面的初始数据
   */
  data: {    
    address:"群星苑",
   
    imgUrls: [
      { goods_showimg: '/../../images/banner.png' },
      { goods_showimg:'/../../images/banner.png'},
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 1000,
    // goods_showimg:[
    //   '/../../images/banner.png',
    //   '/../../images/banner.png',
    // ],
    // 商品类型
    commoditybox: [
      { "commoditytitle": "今日爆款","index":1},
      { "commoditytitle": "水果生鲜", "index": 2},
      { "commoditytitle": "肉蛋禽类", "index": 3 },
      { "commoditytitle": "休闲零食", "index": 4 },
      { "commoditytitle": "休日爆款", "index": 5 }
    ],
    commodity:1,
    goodsimg:"/images/hot.png",
    num: 1,
    goodsbox:[
      { 
        "goodsImage": "/images/goods1.png", 
        "goodsboxTitle": "商品大标题十五个字符以内显示一行",
        "goodsboxTitleMin": "小标题20个字符，最多两行", 
        "remaining": "100", 
        "nowpice": "16.6", 
        "oldpice": "25.6",
        "minusStatus": "disable",
        "num":'1',
        "names":"one"
        },
      {
        "goodsImage": "/images/goods1.png",
        "goodsboxTitle": "商品大标题十五个字符以内显示一行",
        "goodsboxTitleMin": "小标题20个字符，最多两行",
        "remaining": "100",
        "nowpice": "16.6",
        "oldpice": "25.6",
        "minusStatus": "disable",
        "num": '1',
        "names": "two"
      }
    ],
    // 新人专享
    newExclusiveBg:"/images/newExclusive.png",
    coupons:"30",
    showView: true
   
  },
  //选择地址
  toChooseAdd:function(){
    console.log(124)
    wx.navigateTo({
      url: '/pages/positioning/positioning',
    })
  },
  //搜索地址
  thesearch:function(){
    wx.navigateTo({
      url: '/pages/locationSearch/locationSearch',
    })
  },

  //轮播
  // swiper: function () {
  //   var that = this;
  //   wx: wx.request({
  //     url: 'http://d110.ichuk.com/?api/getshufflinggoods',
  //     data: {},
  //     header: { 'Content-Type': 'application/json' },
  //     method: 'POST',
  //     dataType: 'json',
  //     responseType: 'text',
  //     success: function (res) {
  //       that.setData({
  //         imgUrls: res.data.data
  //       })
  //     },
  //     fail: function (res) {

  //     },
  //     complete: function (res) { },
  //   })
  // },
  //   //end

// 商品类型  
  changeOil: function (options){
    var that = this
    var id = options.currentTarget.dataset.id;
    console.log(options)
    console.log(id)
    //设置当前样式
    that.setData({
      'commodity': id
    })
  },
  /*点击减号*/
  bindMinus: function (e) {
    var that = this;
    var arr_key = e.currentTarget.dataset.key;
    var goodsbox = this.data.goodsbox;
    var num = goodsbox[arr_key].num;
    if (num > 1) {
      num--;
    };
    goodsbox[arr_key].num = num;
    goodsbox[arr_key].minusStatus = goodsbox[arr_key].num > 1 ? 'normal' : 'disable';
    var theminusStatus = goodsbox[arr_key].minusStatus;
    that.setData({
      goodsbox: goodsbox,
      minusStatus: theminusStatus
    })
  },
  /*点击加号*/
  bindPlus: function (e) {
    var that = this;    
    var arr_key = e.currentTarget.dataset.key;
    var goodsbox = that.data.goodsbox;
    var num = goodsbox[arr_key].num;
    num++;
    goodsbox[arr_key].num = num;
    goodsbox[arr_key].minusStatus = goodsbox[arr_key].num > 1 ? 'normal' : 'disable';
    var theminusStatus = goodsbox[arr_key].minusStatus;
    that.setData({
      goodsbox: goodsbox,
      minusStatus: theminusStatus,
    })
  },
  /*输入框事件*/
  bindManual: function (e) {
    var num = e.detail.value;
    var minusStatus = num > 1 ? 'normal' : 'disable';    
    this.setData({
      num: num,
      minusStatus: minusStatus
    })
  },

  //隐藏优惠券
  hideExclusive: function(){
    var that = this;
    that.setData({
      showView:"none"
    })
  },

  //获取手机号成为用户
  chooseit: function(e){
    var that = this;
    console.log(e)
    var choosename = e.currentTarget.dataset.name;
    that.setData({
      showUser: "none"
    });
    if (choosename == "允许"){
      console.log("允许")
      console.log(choosename)
    }else{
      console.log("拒绝")
    }
  },
  //权限选择
  permissionsChoose: function(e){
    var that = this;
    console.log(e)
    var choosename = e.currentTarget.dataset.name;
    that.setData({
      showPermissions: "none"
    });
    if (choosename == "允许") {
      console.log("允许")
      console.log(choosename)
    } else {
      console.log("拒绝")
    }
  },




  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //调用封装的方法，为了方便我直接在页面加载的时候执行这个方法
    call.getData('lunbo.do', this.shuffleSuc, this.fail);
  },  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    showView: "block"; //优惠券显示
    wx.showToast({
      title: '你已经不是新人啦',
      icon: 'none',
      duration: 1000
    })
    wx.showToast({
      title: '领取成功',
      icon: 'none',
      duration: 1000
    })

    // setTimeout(function () {
    //   wx.hideToast()
    // }, 2000)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})